-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Dereference one less on search_is_some and make it auto-fixable #4454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@flip1995 do you think this is enough, or is some logic required? I can make it auto fixable once everything else works 😉 How can I run doc tests? |
I think you'll first have to change to the |
I though this would be easier and the code better to understand. But it seems that I am not capable of fixing the issue 😢 |
Your not really far from the goal, and I'm happy to support you to achieve it!
For test cases, see Playground |
Thanks. That worked 😃 |
@flip1995 thank you for the help 👍 Are you sure I need |
Huh, I'm pretty sure that you need It should find a match for |
it seems like the lint isn't very exact. This causes rust-fix to replace everything with just
Or did I do something wrong? |
Rustfix always replaces the span you specify with the suggested code. You have to build the span by hand, since it does not exist in the way you need it. This shouldn't be a problem though. Just search in the |
so I should be able to replace |
No, because the You only want to replace the I just looked up how to get this span, and saw, that it is not that easy (and not really easy to explain the changes that need to be made). So I decided to write a patch for you, that simplifies this. (I'll notify you once it's ready) While looking into this, I found, that there already exists a function to get the name of the closure arg: rust-clippy/clippy_lints/src/utils/mod.rs Lines 916 to 922 in 949b347
You can just use this. |
Here's the patch: https://github.com/flip1995/rust-clippy/commits/method_calls_spans You can look at the second to last commit on the branch on how to use the method spans. Just |
☔ The latest upstream changes (presumably #4462) made this pull request unmergeable. Please resolve the merge conflicts. |
almost worked |
☔ The latest upstream changes (presumably #4408) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry about the merge conflict, let me know if I can help resolving it =) |
That was my fault in 6035b65, so I'd also resolve it for you, if need be. |
Done 👍 |
Could you add a test case where let _ = vec.iter().find(|x| **x == 0).is_some(); |
Ok one last change and a run of |
Thanks! @bors r+ |
📌 Commit 64cd9e4 has been approved by |
Dereference one less on search_is_some and make it auto-fixable Fixes #4453 changelog: none
☀️ Test successful - checks-travis, status-appveyor |
Previously the program only fixed the code when the closure supplied to the function contained only 1 line. This patch removes the restriction. The code already works. This patch only removes the extra check that causes the restriction. The test cases that can now be fixed are moved into the files containing tests cases that can be fixed. The extra check has survived in the code this way. - In Dec 2015, patch a6bd2d0, pull request rust-lang#524. The lint was first added. The program did not support fixing code automatically yet. So the suggested fix was printed as a part of the diagnostic message. When the original code contained multiple lines, the suggested fix was omitted in order to keep the diagnostic message concise. - In May 2019, patch bd0b75f, pull request rust-lang#4049. Logic was added to strip the reference in the closure when the suggested replacement method required it. Because the fix was still only printed when the code contained a single line, the new transformation was only done when the code contained a single line. - In Aug 2019, patch 945d4cf, pull request rust-lang#4454. The lint was updated to fix code automatically. Because the fixed code had only been printed in the diagnostic message for a single line, the fix was only added for a single line. - In Nov 2021, patch 092fe20, pull request rust-lang#7463. The logic for transforming the closure was moved into another file. A comment was added saying that it was only good for a single line because it had only been used for a single line. changelog: [`search_is_some`] now fixes code spanning multiple lines
Previously the program only fixed the code when the closure supplied to the method contained only 1 line. This patch removes the restriction. The code already works. This patch only removes the extra check that causes the restriction. The test cases that can now be fixed are moved into the files containing tests cases that can be fixed. The extra check has survived in the code this way. - In Dec 2015, patch a6bd2d0, pull request rust-lang#524. The lint was first added. The program did not support fixing code automatically yet. So the suggested fix was printed as a part of the diagnostic message. When the original code contained multiple lines, the suggested fix was omitted in order to keep the diagnostic message concise. - In May 2019, patch bd0b75f, pull request rust-lang#4049. Logic was added to strip the reference in the closure when the suggested replacement method required it. Because the fix was still only printed when the code contained a single line, the new transformation was only done when the code contained a single line. - In Aug 2019, patch 945d4cf, pull request rust-lang#4454. The lint was updated to fix code automatically. Because the fixed code had only been printed in the diagnostic message for a single line, the fix was only added for a single line. - In Nov 2021, patch 092fe20, pull request rust-lang#7463. The logic for transforming the closure was moved into another file. A comment was added saying that it was only good for a single line because it had only been used for a single line. changelog: [`search_is_some`] now fixes code spanning multiple lines
Previously the program only fixed the code when the closure supplied to the method contained only 1 line. This patch removes the restriction. The code already works. This patch only removes the extra check that causes the restriction. The test cases that can now be fixed are moved into the files containing tests cases that can be fixed. The unnecessary check has survived in the code this way. - In Dec 2015, patch a6bd2d0, pull request rust-lang#524. The lint was first added. The program did not support fixing code automatically yet. So the suggested fix was printed as a part of the diagnostic message. When the original code contained multiple lines, the suggested fix was omitted in order to keep the diagnostic message concise. - In May 2019, patch bd0b75f, pull request rust-lang#4049. Logic was added to strip the reference in the closure when the suggested replacement method required it. Because the fix was still only printed when the code contained a single line, the new transformation was only done when the code contained a single line. - In Aug 2019, patch 945d4cf, pull request rust-lang#4454. The lint was updated to fix code automatically. Because the fixed code had only been printed in the diagnostic message for a single line, the fix was only added for a single line. - In Nov 2021, patch 092fe20, pull request rust-lang#7463. The logic for transforming the closure was moved into another file. A comment was added saying that it was only good for a single line because it had only been used for a single line. changelog: [`search_is_some`] now fixes code spanning multiple lines
Fixes #4453
changelog: none